<?php

use App\Admin;
use App\User;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Modules\Admin\Entities\Chatgroup;

class AdminSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //初始化客服组
        $chatgroup = new Chatgroup();
        $chatgroup->fill([
            'groupname'=> '默认客服组',
            'groupname_en'=> 'default group',
            'description' => '这是默认客服组',
            'sort' => 0
        ])->save();
        $gid = $chatgroup->getKey();

        $users = factory(Admin::class,2)->create();
        $userone = $users[0];
        $userone->name = 'wkk';
        $userone->nickname = '老王';
        $userone->gid = $gid;
        $userone->save();

        $usertwo = $users[1];
        $usertwo->name = 'mwl';
        $usertwo->nickname = '喵喵';
        $usertwo->gid = $gid;
        $usertwo->save();

        Role::create([
            'title'=>'站长',
            'name'=>'webmaster',
            'guard_name'=>'admin'
        ]);

        Role::create([
            'title'=>'组长',
            'name'=>'groupleader',
            'guard_name'=>'admin'
        ]);

        $userone->assignRole('webmaster');
        $usertwo->assignRole('groupleader');
    }
}
